//管理员--表现层
var express = require('express');
var router = express.Router();
const {login,get,create,getById,update,deleted,search} = require("../service/adminsService.js");

//登录验证
router.post('/login', async function (req, res, next) {
    const params = req.body;
    console.log(params,"get")
    const data = await login(params)
    res.send(data);
});
//获取数据
router.get('/', async function (req, res, next) {
    const params = req.query;
    const data = await get(params)
    res.send(data);
});
//新增
router.post('/create', async function (req, res, next) {
    const params = req.body;
    console.log(params,"careate")
    const data = await create(params);
    res.send(data);
});
//更新
router.patch('/', async function (req, res, next) {
    const { _id } = req.body;
    const parameter = req.body;
    console.log(req.body,"router")
    console.log({ _id },parameter,"router")
    let data = await update(_id, parameter)
    res.send(data);
});
//通过id取数据
router.get('/:_id', async function (req, res, next) {
    const {
        _id
    } = req.params;
    const data = await getById(_id);
    // console.log(data);
    res.send(data);
});
//删除
router.post('/dele', async function (req, res, next) {
    console.log(req.body)
    const {_id} = req.body;
    const result = await deleted(_id);
    res.send(result);
});
//搜索数据
router.post('/search', async function (req, res, next) {
    console.log(req.body)
    const params = req.body;
    const data = await search(params)
    res.send(data);
});



module.exports = router;